package com.nokia.ion.sdu.cdr_decoder;

import java.util.concurrent.CountDownLatch;

/**
 * Created by vicwang on 2016/8/24.
 */
public class LoopPrint extends Thread {
    private int threadNum;

    private CountDownLatch countDownLatch;
    
    public class Info {
        public String file = "";
        public long size;
        public long avalible;
    }

    public static Info[] infos;

    public static boolean run = true;

    public LoopPrint(int threadNum, CountDownLatch countDownLatch) {
        this.threadNum = threadNum;
        this.countDownLatch = countDownLatch;

        infos = new Info[threadNum];
        for (int i = 0; i < threadNum; i++) {
            infos[i] = new Info();
        }
    }

    @Override
    public void run() {
        while (run) {
            for (Info info : infos) {
                if (info.file == null || info.file.isEmpty()) {
                    continue;
                }

                double p = (float) (info.size - info.avalible) / info.size * 100;
                System.out.println(String.format("decoding %s ...... -> %d", info.file, (int)p) + "%");
            }
            System.out.println("-------------------------------------------------------------------------------------");
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                run = false;
            }
        }
        System.out.println("LoopPrint thread exit.");
        countDownLatch.countDown();
    }
}
